<?php
namespace App\Admin\Renderable;

use App\Admin\Repositories\User\WxUser;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UsersRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxUser(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->simplePaginate();
            $grid->model()->orderBy('id', 'desc');
            $grid->quickSearch(['id', 'user_name', 'phone', 'email'])->placeholder('搜索与用户id，用户名，手机号，邮箱...')->width(35);
            $grid->showColumnSelector();
            $grid->column('id')->sortable();
            $grid->column('user_name');
            $grid->column('user_avatar')->image('',50);
//            $grid->column('user_background_maps')->image('',50);
//            $grid->column('user_background_maps');
//            $grid->column('user_introduce');
//            $grid->column('user_birthday');
//            $grid->column('user_mobile');
//            $grid->column('weixin_name')->explode()->label();
//            $grid->column('weixin_openid');
            $grid->column('a','其他')->display('更多内容')->modal('详情',function ($res){
                $user = $this;
                $user->origin_phone = _get_origin_attribute('wx_user', [['id', '=', $user->id]], 'phone');
                return view('admin/user/info',compact('user'));
            });
//            $grid->column('country');
//            $grid->column('province');
//            $grid->column('city');
//            $grid->column('others')->display(function () {
//                return '认证:'. $this->is_authentication .'<br/>'.
//                       '会员' . $this->is_member.'<br/>'.
//                       '官方' . $this->is_official ? '是':'否';
//            });
            $grid->column('gender')->using([0 => '未知',1 => '男',2 => '女'])->label();
//            $grid->column('authentication_id');
            $grid->column('is_official')->switch();
            $grid->column('is_authentication')->switch();
//            $grid->column('is_member')->using([0=>'否',1=>'是'])->label();
            $grid->column('user_state')->using([0=>'正常',1=>'用户注销',2=>'管理员封号'])->label();
//            $grid->column('updated_at','登录时间')->sortable();


            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('user_name');
                $filter->equal('gender')->select([0 => '未知',1 => '男',2 => '女']);
                $filter->equal('is_official')->select([0=>'否',1=>'是']);
            });
            $grid->disableBatchActions();
            $grid->disableActions();
        });
    }
}
